<?php
function basePath($path = '')
{
    return __DIR__.'/'.$path;
}
/**
 * 加载部分视图
 * 
 * @param string $name
 * @return void
 */
function loadPartial($name,$data=[]){
     $partialPath=basePath("APP/views/partials/{$name}.php");
    if(file_exists($partialPath)){
        extract($data);
        require $partialPath;
    }else{
        echo "{$name}部分视图不存在！";
    }
}
/**
 * 加载视图
 * 
 * @param string $name
 * @param array $data
 * @return void
 */
function loadView($name,$data=[]){
    $viewPath = basePath("App/views/{$name}.view.php");
    // inspectAnDie($name);
    // inspectAnDie($viewPath);调试函数
    if(file_exists($viewPath)){
        extract($data);
        require $viewPath;
    }else{
        echo "{$viewPath}视图不存在！";
    }
}

function inspect($value){
    echo '<pre>';
    var_dump($value);
    echo '<pre>';
}

function inspectAnDie($value){
    echo '<pre>';
    die(var_dump($value));
    echo '<pre>';
}
/**
 * @param string
 * @return string
 */
function sanitize($dirty)
{
    return filter_var(trim($dirty),FILTER_SANITIZE_SPECTAL_CHARS);
}
/**
 * @param string
 * @return void
 */
function redirect($url)
{
    header("Location:{$url}");
    exit;
}